$(function () {
    articleList();
});

// 获取文章列表
function articleList(page) {
    $.ajax({
        url: "indeArticleList",
        data: {
            pageNum: page,
            pageSize: 9
        },
        type: 'GET',
        dataType: 'json',
        async: true,
        success: function (data) {
            var list = data.list;
            $("#prePage").val(data.prePage);
            $("#nextPage").val(data.nextPage);
            $("#tailPage").val(data.pages);
            $("#pageNum").text(data.pageNum);
            if(list != null && list.length > 0){
                $("#container").empty();
                var articleDiv = "";
                for(var i=0; i<list.length; i++){
                    var article = "";
                    if(i%3==0){
                       article += "<div class='row'>";
                    }
                    article += "<div class='col-md-4'>" +
                        "   <div class='box-item'>" +
                        "      <div class='entry-thumb'>" +
                        "        <img class='img-responsive' src='"+list[i].imgUrl+"'>" +
                        "        <a class='thumb-link' href='qryById?id="+list[i].articleId+"'><i class='fa fa-link'></i></a>" +
                        "      </div>" +
                        "      <div class='content'>" +
                        "         <h3 class='entry-title'><a href='qryById?id="+list[i].articleId+"'>"+list[i].title+"</a></h3>" +
                        "         <p class='summary'>"+list[i].summary+"</p>" +
                        "         <span>"+list[i].createDate+"</span>" +
                        "      </div>" +
                        "      <div class='read-more'><a href='qryById?id="+list[i].articleId+"'>阅读全文...</a></div>" +
                        "    </div>" +
                        "</div>";
                    if(i>0 && i%3==0){
                        articleDiv += "</div>" + article;
                    }else{
                        articleDiv += article;
                    }
                }
                articleDiv += "</div>";
                $("#container").append(articleDiv);
            }
        },
        error: function (msg) {
            alert("服务器异常，请稍后再试！")
            return;
        }
    });
}

// 首页
function homePage() {
    articleList(1);
}
//上一页
function prePage(){
    var page = $("#prePage").val();
    articleList(page);
}
//下一页
function nextPage(){
    var page = $("#nextPage").val();
    articleList(page);
}
// 尾页
function tailPage() {
    var page = $("#tailPage").val();
    articleList(page);
}